class Solution {
public:
    vector<int> levelOrder(TreeNode* root) {
        if (root == nullptr)
            return {};
        vector<int> nums;
        queue<TreeNode*> q;
        q.push(root);
        while (!q.empty())
        {
            if (q.front()->left)
                q.push(q.front()->left);
            if (q.front()->right)
                q.push(q.front()->right);
            nums.push_back(q.front()->val);
            q.pop();
        }
        return nums;
    }
};